package com.theBlind.orm;

import java.sql.*;
import java.util.List;

/**
 * @program: orm
 * @description:
 * @author: TheBlind
 * @create: 2021-04-23 15:17
 **/
public class BaseExecutor implements Executor {

    Configuration configuration;

    public BaseExecutor(Configuration configuration) {
        this.configuration=configuration;
    }



    @Override
    public <E> List<E> query(MapperStatement ms, Object par) {
        DataSourceProperty dataSource = configuration.getDataSource();
        try {
            Connection connection = DriverManager.getConnection(dataSource.getUrl(), dataSource.getUsername(), dataSource.getPassword());
            PreparedStatement preparedStatement = connection.prepareStatement(ms.getSql());
            ResultSet resultSet = preparedStatement.executeQuery();
            ResultHandle resultHandle = new ResultHandle();
            resultHandle.handlerResultSet(resultSet,ms.getResultType());

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }






}
